# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User as AuthUser
from common.models import BaseEnum
# Create your models here.


class WikiInputFormat(BaseEnum):
    """
    输入类型
    """
    Html = 'html'
    Markdown = 'markdown'


WIKI_INPUT_FORMAT = WikiInputFormat.to_choices()


class Wiki(models.Model):
    title = models.CharField(max_length=1024)
    slug = models.SlugField(max_length=1024)
    display_content = models.TextField()
    input_format = models.CharField(max_length=32, choices=WIKI_INPUT_FORMAT)
    input_content = models.TextField()
    created_by = models.ForeignKey(AuthUser, models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)


from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())


class Snippet(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(
        choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES,
                             default='friendly', max_length=100)

    class Meta:
        ordering = ('created_at',)
